namespace Resharper.Abstractions.CodeDom.Statements.TryStatements
{
  using JetBrains.Annotations;
  using JetBrains.ReSharper.Psi.CSharp.Tree;
  using Resharper.Abstractions.CodeDom.TreeNodes;

  /// <summary>Defines the <see cref="CatchClause"/> class.</summary>
  public class CatchClause : TreeNode
  {
    #region Constructors and Destructors

    /// <summary>Initializes a new instance of the <see cref="CatchClause"/> class.</summary>
    /// <param name="catchClause">The catch clause.</param>
    internal CatchClause([NotNull] ICatchClause catchClause) : base(catchClause)
    {
    }

    #endregion

    #region Properties

    /// <summary>
    /// Gets the name of the escaped exception type.
    /// </summary>
    [NotNull]
    public string EscapedExceptionTypeName
    {
      get
      {
        return this.ExceptionTypeName.Replace("<", "{").Replace(">", "}");
      }
    }

    /// <summary>
    /// Gets the type of the exception.
    /// </summary>
    public string ExceptionTypeName
    {
      get
      {
        var exceptionType = this.InternalCatchClause.ExceptionType;

        return exceptionType != null ? exceptionType.GetClrName().FullName : string.Empty;
      }
    }

    /// <summary>
    /// Gets the internal for statement.
    /// </summary>
    [NotNull]
    internal ICatchClause InternalCatchClause
    {
      get
      {
        return (ICatchClause)this.InternalTreeNode;
      }
    }

    #endregion
  }
}